<!DOCTYPE html>
<html>
	<head>
		 <meta charset="utf-8">
        <title>后台管理模板</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
        <link rel="stylesheet" href="../../css/global.css" media="all">
        <link rel="stylesheet" type="text/css" href="http://www.jq22.com/jquery/font-awesome.4.6.0.css">
        <link rel="stylesheet" href="../../datatables/media/css/jquery.dataTables.css">
        <link rel="stylesheet" href="../../datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css">
        <link rel="stylesheet" type="text/css" href="../../css/dateRange.css">
		<style type="text/css">
		.voucher-content {
			margin-top: 65px;
		margin-left: 40px;
		font-size: 14px
		}
		table.dateRangeDateTable th:first-child, table.dateRangeDateTable td:first-child {
            width: inherit;
        }
		</style>
	</head>
	<body>
		<div class="layui-layout layui-layout-admin" style="border-bottom: solid 5px #1aa094;">
			<!--头部导航-->
			<div class="layui-header header header-demo" ></div>
			<!--左侧导航-->
			<div class="layui-side layui-bg-black" id="admin-side">
			</div>
			<!--右侧具体内容-->
			<div class="layui-body" style="bottom: 0;border-left: solid 2px #1AA094;padding:20px" id="admin-body">
				<div>
					<div class="title">编辑代金券</div>
				</div>
				<hr/>
				<div class="voucher-content">
					<form class="layui-form" action="">
						<div class="layui-form-item" style="margin-right: 800px">
							<label class="layui-form-label">代金券名称</label>
							<div class="layui-input-block">
								<input type="text" name="voucherName" required  lay-verify="required"  autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item" style="margin-right: 800px">
							<label class="layui-form-label">代金券金额</label>
							<div class="layui-input-block">
								<input type="text" name="voucherPrice" required  lay-verify="required"  autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item" style="margin-right: 800px">
							<label class="layui-form-label">所需积分</label>
							<div class="layui-input-block">
								<input type="text" name="voucherScore" required  lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item" style="margin-right: 800px">
							<label class="layui-form-label">日期区间</label>
							<div class="layui-input-block">
								<div class="ta_date" id="div_date_demo3">
									<span class="date_title" id="date_demo3">2017-07-13 至 2017-07-19</span>
									<a class="opt_sel" id="input_trigger_demo3" href="#">
										<i class="i_orderd"></i>
									</a>
								</div>
							</div>
						</div>
					</form>
						<div class="layui-form-item">
							<div class="layui-input-block">
								<button class="layui-btn" lay-submit lay-filter="formDemo" id="confirmedit">确认修改</button>
							</div>
						</div>
				</div>
				<!--底部导航-->
            <div class="layui-footer footer footer-demo" id="admin-footer"></div>
            <!--JS模块-->
            <script type="text/javascript" src="../../layui/layui.js"></script>
            <script src="../../js/jquery-1.12.3.min.js"></script>
            <script src="../../js/index.js"></script>
            <script type="text/javascript" src="../../js/jquery.cookie.js"></script>
            <script type="text/javascript" src="../../js/dateRange.js"></script>
				<script>
				var data = {
					"code": 200,
					"vouchersName": "抵用券-满30立减",
					"vouchersPrice": "5",
					"vouchersFailuretime": 1500859170806,
					"vouchersState": 33187,
					"vouchersDate": 7,
					"vouchersScore": 3000,
					"vouchersType": 17604
				}
				Date.prototype.Format = function(fmt) { //author: meizz 
					var o = {
						"M+": this.getMonth() + 1, //月份 
						"d+": this.getDate(), //日 
						"h+": this.getHours(), //小时 
						"m+": this.getMinutes(), //分 
						"s+": this.getSeconds(), //秒 
						"q+": Math.floor((this.getMonth() + 3) / 3), //季度 
						"S": this.getMilliseconds() //毫秒 
					};
					if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
					for (var k in o)
						if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
					return fmt;
				}

				layui.use('form', function() {
					var form = layui.form();
					C1 = window.location.href.split("?")[1];
					voucherId = C1.split("=")[1];
					alert(C1);
					alert(voucherId)
					var dateRange

					/*$.ajax({
                                     type: "get",
                                     url: "/randomdelivery/VoucherController/voucher/"+voucherId,
                                     data: {},
                                     async: true,
                                     dataType: "json",
                                     contentType: "application/json",
                                     success: function(data) {*/
					if (data.code == 200) {
						$("input[name='voucherName']").val(data.vouchersName)
						$("input[name='voucherPrice']").val(data.vouchersPrice)
						$("input[name='voucherScore']").val(data.vouchersScore)
						var Startime = new Date(data.createTime).Format("yyyy-MM-dd ") //传一个创建时间
						var Failuretime = new Date(data.vouchersFailuretime).Format("yyyy-MM-dd ") //传一个创建时间
						dateRange = new pickerDateRange('date_demo3', {
							isTodayValid: true,
							startDate: Startime,
							endDate: Failuretime,
							defaultText: ' 至 ',
							inputTrigger: 'input_trigger_demo3',
							theme: 'ta',
							success: function(obj) {}
						});
					};
					/*},
                                Error: function() {
                                    alert("服务器出错");
                                }
                            });*/

					$("#confirmedit").on("click", function() {
						/*$.ajax({
                                     type: "POST",
                                     url: "/randomdelivery/VoucherController",
                                     data: JSON.stringify({
											"vouchersName": $("input[name='voucherName']").text(),
											"vouchersPrice": $("input[name='voucherPrice']").text(),
											"vouchersScore": $("input[name='voucherScore']").text(),
											"vouchersFailuretime": endDate,
											"vouchersDate": vouchersDate,
											"vouchersState": 1,
											"vouchersType": 1
									}),
                                     async: true,
                                     dataType: "json",
                                     contentType: "application/json",
                                     success: function(data) {*/
						if (data.code == 200) {
							window.location.href = "voucher.html"
						};
						/*},
	                                Error: function() {
	                                    alert("服务器出错");
	                                }
	                            });*/
					})


				});
				</script>
			</div>
		</div>
	</body>
</html>